﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace Halfwit.Converters
{
    public class TweetWidthConverter : IValueConverter
    {
        public TweetWidthConverter()
        {
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var windowWidth = System.Convert.ToDouble(value);
            var optimumWidth = Properties.Settings.Default.TweetWidth;

            // anything less than OptumumWidth, don't set a MaxWidth
            var columns = (int)(windowWidth / optimumWidth);
            if (columns == 0) return DependencyProperty.UnsetValue;

            // anything over n * OptimumWidth, return Width / n
            return windowWidth / columns;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
